package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TicketSeal;
import com.ruoyi.system.service.ITicketSealService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 印章信息Controller
 *
 * @author ruoyi
 * @date 2024-07-15
 */
@RestController
@RequestMapping("/system/seal")
public class TicketSealController extends BaseController
{
    @Autowired
    private ITicketSealService ticketSealService;

    /**
     * 查询印章信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:seal:list')")
    @GetMapping("/list")
    public TableDataInfo list(TicketSeal ticketSeal)
    {
        startPage();
        List<TicketSeal> list = ticketSealService.selectTicketSealList(ticketSeal);
        return getDataTable(list);
    }

    /**
     * 导出印章信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:seal:export')")
    @Log(title = "印章信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TicketSeal ticketSeal)
    {
        List<TicketSeal> list = ticketSealService.selectTicketSealList(ticketSeal);
        ExcelUtil<TicketSeal> util = new ExcelUtil<TicketSeal>(TicketSeal.class);
        util.exportExcel(response, list, "印章信息数据");
    }

    /**
     * 获取印章信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:seal:query')")
    @GetMapping(value = "/{sealNo}")
    public AjaxResult getInfo(@PathVariable("sealNo") String sealNo)
    {
        return success(ticketSealService.selectTicketSealBySealNo(sealNo));
    }

    /**
     * 新增印章信息
     */
    @PreAuthorize("@ss.hasPermi('system:seal:add')")
    @Log(title = "印章信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TicketSeal ticketSeal)
    {
        ticketSeal.setCreateBy(getUsername());
        return toAjax(ticketSealService.insertTicketSeal(ticketSeal));
    }

    /**
     * 修改印章信息
     */
    @PreAuthorize("@ss.hasPermi('system:seal:edit')")
    @Log(title = "印章信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TicketSeal ticketSeal)
    {
        ticketSeal.setUpdateBy(getUsername());
        return toAjax(ticketSealService.updateTicketSeal(ticketSeal));
    }

    /**
     * 删除印章信息
     */
    @PreAuthorize("@ss.hasPermi('system:seal:remove')")
    @Log(title = "印章信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{sealNos}")
    public AjaxResult remove(@PathVariable String[] sealNos)
    {
        return toAjax(ticketSealService.deleteTicketSealBySealNos(sealNos));
    }
}

